/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.iftk.xmlparser.domain;

/**
 *
 * @author Tomi
 */
public class ResearchGroup extends BubbleItem {
    private String name;
    private String investigator;
    private String description;

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getInvestigator() {
        return investigator;
    }

    public void setInvestigator(String investigator) {
        this.investigator = investigator;
    }

    public String getName() {
        return name;
    }
    
    public String getLastName() {
        if(!investigator.isEmpty()) {
            String[] tokens = investigator.split(",");
            return tokens[0];            
        }
        return null;
    }
    
    public String getInitial() {
        if(!investigator.isEmpty()) {
            String[] tokens = investigator.split(",");
            String result = tokens[1];
            result = result.trim();
            String temp = result.substring(0, 1);
            result = temp;
            return result;
        }
        return null;
    }

    public void setName(String name) {
        this.name = name;
    }
    
    @Override
    public String toString() {
        StringBuilder result = new StringBuilder();
        String NEW_LINE = System.getProperty("line.separator");
        
        result.append(this.getClass().getName()).append("Object {").append(NEW_LINE);   
        result.append(" ID: ").append(getId()).append(NEW_LINE);
        result.append(" Name: ").append(name).append(NEW_LINE);
        result.append(" Investigator: ").append(investigator).append(NEW_LINE);
        result.append(" Description: ").append(description).append(NEW_LINE);
        result.append(" Last name: ").append(getLastName()).append(NEW_LINE);
        result.append(" Initial: ").append(getInitial()).append(NEW_LINE);
        result.append(" Links: ");
        for(Integer i : getLinks()) {
            result.append(i).append("\t");
        } 
        result.append(NEW_LINE);        
        result.append("}");
        
        return result.toString();
    }
    
    @Override
    public String toBubble() {
        StringBuilder result = new StringBuilder();
        String NEW_LINE = System.getProperty("line.separator");
        
        result.append("<bubble>").append(NEW_LINE);
        result.append("\t<id>").append(getId()).append("</id>").append(NEW_LINE);
        result.append("\t<titletext>").append(name).append("</titletext>").append(NEW_LINE);
        result.append("\t<titlefontsize>10</titlefontsize>").append(NEW_LINE);
        result.append("\t<shorttext fontsize=\"4\">").append(name).append(NEW_LINE).append("Principal investigator: ").
                append(investigator).append("</shorttext>").append(NEW_LINE);
        result.append("\t<style>BlackLevel2</style>").append(NEW_LINE);
        result.append("\t<links>");
        for(int i = 0; i < getLinks().size(); i++) {
            if(i == getLinks().size()-1) {
                result.append(getLinks().get(i));
            }
            else {
                result.append(getLinks().get(i)).append(",");
            }
        }
        result.append("</links>").append(NEW_LINE);
        result.append("<priority>3</priority>").append(NEW_LINE);
        result.append("</bubble>").append(NEW_LINE);
        
        return result.toString();
    }
}
